package com.imcode.filedemo;

/**
 * 递归是方法自己调用自己
 * 递归要有出口
 */
public class DiGuiDemo01 {

    public static void main(String[] args) {
        long s1 = System.currentTimeMillis();
        test02(10000);
        long s2 = System.currentTimeMillis();


        long s3 = System.currentTimeMillis();
        test03(10000);
        long s4 = System.currentTimeMillis();

        System.out.println();
        System.out.println("递归：" + (s2-s1));
        System.out.println("循环：" + (s4-s3));
    }


    //java.lang.StackOverflowError
    public static void test01() {
        // System.out.println("Hello");
        test01();
    }

    public static void test02(int i) {
        System.out.print(i);
        // 方法调用结束
        if (i == 0) {
            return;
        }
        test02(--i);
    }
    public static void test03(int i){
        while (i>=0){
            System.out.print(i--);
        }
    }
}
